
function tst_email(email){

	var ok = email.search(/^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/);
	
	if (ok == 0){ 
		$("#regmailerr").css("visibility","hidden");
		return true;
	}
	else{ 
		$("#regmailerr").css("visibility","visible");
		return false;
	}
}

function tst_name_lname_uname(name, lname, uname){
		
	var okname;
	var oklname;
	var okuname;
	
	okname = name.search(/^[a-�A-�]+$/);
	oklname = lname.search(/^[a-�A-�]+$/);
	okuname = uname.search(/^[a-�A-�]+$/);

	var ret = true;
	if (okname != 0){
		$("#regnameerr").css("visibility","visible");
		ret = false;
	} else $("#regnameerr").css("visibility","hidden");
	if (oklname != 0){
		$("#reglnameerr").css("visibility","visible");
		ret = false;
	} else $("#reglnameerr").css("visibility","hidden");
	if (okuname != 0){
		$("#regunameerr").css("visibility","visible");
		ret = false;
	} else $("#regunameerr").css("visibility","hidden");
	return ret;
}

function tst_pass(pass1, pass2){
	
	if(pass1 == "" || pass2 == ""){
		$("#regpasserr").css("visibility","visible");
		return false;
	}
	else if (pass1 == pass2){	
		$("#regpasserr").css("visibility","hidden");
		return true;		
	}
	else{	
		$("#regpasserr").css("visibility","visible");
		return false;
	}
}

function validiraj(event){
	
	var email = document.getElementById("regmail" ).value;
	var name  = document.getElementById("regname" ).value;
	var lname = document.getElementById("reglname").value;
	var uname = document.getElementById("reguname").value;
	var pass1 = document.getElementById("regpass" ).value;
	var pass2 = document.getElementById("regcpass").value;	
	
	var okmail = tst_email(email);
	var okname = tst_name_lname_uname(name, lname, uname);
	var okpass = tst_pass(pass1, pass2);
	
	if ( !okmail || !okname || !okpass ){
		event.preventDefault();
		return false;			
	}else{
		//alert("Uspesno ste se registrirali!");
		//window.location.href="./index.php";
		return true;
	}		
}

var gumb = document.getElementById("register");
gumb.addEventListener( "click", validiraj, false);